home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir36 / getclr10.zip / README < prev   
Text File  |  1994-01-10  |  8KB  |  182 lines

  1.                                  
  2.                                  GET COLORS
  3.                                 Version 1.0 
  4.                               January 10, 1994
  5.  
  6. FREEWARE for evaluation and use by anyone who may be interested.  Please
  7. see comments below.
  8.  
  9. UPLOAD AUTHOR: Richard Simpson (CompuServe #73353,2204).
  10.  
  11. PURPOSE: To save a user's (unknown) screen colors at the beginning of
  12. a batch file, so that they can be reset at the end of the batch file.
  13.  
  14. FILE LIST:
  15.      DEMO.BAT        Run and examine for example.
  16.      GETCOLOR.BAT    Called from DEMO.BAT and contains IF statements.
  17.      GET-FORE.COM    Detects foreground color and returns errorlevel.
  18.      GET-BACK.COM    Detects background color and returns errorlevel.
  19.      GET-BOLD.COM    Detects bold attribute and returns errorlevel.
  20.      README          This file.
  21.  
  22. INSTRUCTIONS:  Anyone familiar with DOS batch files and setting colors
  23. in batch files will easily see how this utility works simply by looking at
  24. the two batch files included.  Start with DEMO.BAT, which is a substitution
  25. for your real batch file.  DEMO.BAT calls GETCOLOR.BAT near the beginning.
  26. By having your batch file call GETCOLOR.BAT, you won't have to retype the
  27. contents into your batch file.  GETCOLOR.BAT runs the three COM files
  28. which detect the screen attributes and return the attributes as errorlevels.
  29. The attributes are saved as DOS environment variables.  At the end of
  30. DEMO.BAT, the attributes are reset using ANSI escape sequences with the
  31. previously set environment variables.  (Of course, ANSI.SYS must be loaded.)
  32.  
  33. COMMENTS:  This is my first software upload.  I'm just beginning to try
  34. to teach myself programming.  My first attempt at writing this utility
  35. consisted of one COM file to detect all the screen attributes.  One
  36. problem with it was that GETCOLOR.BAT then required 128 lines of IF
  37. ERRORLEVEL statements.  I posted a message on the IBMPRO forum, Assembler
  38. section, asking for ideas to improve this utility (and acknowledging that
  39. I'm just a beginner).  Peter Below (CompuServe #100113,1101) was one of
  40. the members who answered, and he pointed out that I could reduce the number
  41. of IF ERRORLEVEL statements by having separate programs to detect the
  42. foreground and background.  He gave me the source code set out below for
  43. detecting the foreground and background.  From there, I was able to write
  44. the program to detect the bold attribute.
  45.  
  46.      Peter also suggested avoiding the need for the IF ERRORLEVEL statements
  47. in the batch file by having one program write the attribute values to a file
  48. and having another program read the file, build the ANSI sequences, and write
  49. to the DOS standard output.  I haven't learned enough yet to know how to do
  50. that.  If I keep learning, I'll try that approach.
  51.  
  52.      Anyone who has any comments is encouraged to send them to me directly
  53. (CompuServe #73353,2204) or post them in the IBMPRO forum.  My original
  54. request for help appeared in a message thread called Small Pgramming Problem
  55. (message #105639).  The following may be of interest to other beginners:
  56.  
  57.                              Attribute Byte
  58.    ┌─────────Background──────────┐     ┌─────────Foreground──────────┐
  59.  ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐
  60.  │  7   │ │  6   │ │  5   │ │  4   │ │  3   │ │  2   │ │  1   │ │  0   │
  61.  │Blink │ │ Red  │ │Green │ │ Blue │ │Bright│ │ Red  │ │Green │ │ Blue │
  62.  └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘
  63.  
  64.            Binary Bits    Decimal   ANSI Foreground   ANSI Background
  65.  Black        0 0 0          0           30                40
  66.  Blue         0 0 1          1           34                44
  67.  Green        0 1 0          2           32                42
  68.  Cyan         0 1 1          3           36                46
  69.  Red          1 0 0          4           31                41
  70.  Magenta      1 0 1          5           35                45
  71.  Yellow       1 1 0          6           33                43
  72.  White        1 1 1          7           37                47
  73.  
  74.  
  75.      GET-FORE.COM (File size is F hex or 15 decimal)
  76.  
  77. MOV AH,8       ;BIOS int 10/8 returns attribute at cursor in AH
  78. XOR BH,BH      ;Screen page 0
  79. INT 10
  80. AND AH,7       ;Keep only lower 3 bits
  81. XCHG AL,AH     ;Prepare AL for errorlevel
  82. MOV AH,4C
  83. INT 21
  84.  
  85.      
  86.      GET-BACK.COM  (File size is 13 hex or 19 decimal)
  87.  
  88. MOV AH,8       ;BIOS int 10/8 returns attribute at cursor in AH
  89. XOR BH,BH      ;Screen page 0
  90. INT 10
  91. MOV CL,4       ;Shift color 4 bits to right to get
  92. SHR AH,CL      ;background color in low nibble
  93. AND AH,7       ;Keep only lower 3 bits
  94. XCHG AL,AH     ;Prepare AL for errorlevel
  95. MOV AH,4C
  96. INT 21         
  97.  
  98.      
  99.      GET-BOLD.COM  (File size is 13 hex or 19 decimal)
  100.  
  101. MOV AH,8       ;BIOS int 10/8 returns attribute at cursor in AH
  102. XOR BH,BH      ;Screen page 0
  103. INT 10
  104. MOV CL,4       ;Shift color 3 bits to right to get
  105. SHR AH,CL      ;4th bit (bit 3) in 1st bit (bit 0) position
  106. AND AH,7       ;Keep only 1st bit (bit 0)
  107. XCHG AL,AH     ;Prepare AL for errorlevel
  108. MOV AH,4C
  109. INT 21         
  110.  
  111.  
  112. The following shows two examples of the effect on the registers as 
  113. GET-BOLD.COM is stepped through, with colors set as specified:
  114.  
  115. Example #1:  Yellow on White (no bold used)
  116.  
  117.                Backgrnd  Foregrnd
  118.   Binary       0 1 1 1    0 1 1 0
  119.   Hex             7          6
  120.   Decimal         7          6
  121.  
  122. INSTRUCTION                   REGISTERS AFTER EXECUTION
  123.  
  124. MOV     AH,08                 AX=0800  BX=0000  CX=0013  
  125.  
  126. XOR     BH,BH                 AX=0800  BX=0000  CX=0013  
  127.  
  128. INT     10                    AX=7620  BX=0000  CX=0013
  129.  
  130. MOV     CL,03                 AX=7620  BX=0000  CX=0003  
  131.  
  132. SHR     AH,CL                 AX=0E20  BX=0000  CX=0003  
  133.  
  134.      After shifting 3 bits to right, binary changes from
  135.      0111-0110 to 0000-1110, and hex changes from 76 to 0E.
  136.  
  137. AND     AH,01                 AX=0020  BX=0000  CX=0003  
  138.  
  139.      After keeping only first digit, binary changes from
  140.      0000-1110 to 0000-0000 and hex changes from 0E to 00.
  141.  
  142. XCHG    AL,AH                 AX=2000  BX=0000  CX=0003  
  143.  
  144. MOV     AH,4C                 AX=4C00  BX=0000  CX=0003  
  145.  
  146. INT     21                    Program terminated normally                                                     
  147.  
  148. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  149.  
  150. Example #2:  Bright Yellow on Blue
  151.  
  152.                Backgrnd  Foregrnd
  153.   Binary       0 0 0 1    1 1 1 0
  154.   Hex             1          E
  155.   Decimal         1         14
  156.  
  157. INSTRUCTION                   REGISTERS AFTER EXECUTION
  158.  
  159. MOV     AH,08                 AX=0800  BX=0000  CX=0013  
  160.  
  161. XOR     BH,BH                 AX=0800  BX=0000  CX=0013  
  162.  
  163. INT     10                    AX=1E20  BX=0000  CX=0013  
  164.  
  165. MOV     CL,03                 AX=1E20  BX=0000  CX=0003  
  166.  
  167. SHR     AH,CL                 AX=0320  BX=0000  CX=0003  
  168.  
  169.      After shifting 3 bits to right, binary changes from
  170.      0001-1110 to 0000-0011, and hex changes from 1E to 03.
  171.  
  172. AND     AH,01                 AX=0120  BX=0000  CX=0003  
  173.  
  174.      After keeping only first digit, binary changes from
  175.      0000-0011 to 0000-0001 and hex changes from 03 to 01.
  176.  
  177. XCHG    AL,AH                 AX=2001  BX=0000  CX=0003  
  178.  
  179. MOV     AH,4C                 AX=4C01  BX=0000  CX=0003  
  180.  
  181. INT     21                    Program terminated normally                                                     
  182.